package com.example.reflection.realize;

import com.example.reflection.config.InterfaceInvocationHandler;
import com.example.reflection.config.util.ReflexUtil;
import com.example.reflection.service.UserService;
import com.example.reflection.service.impl.UserServiceImpl;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Main {
    private static final String FILE = "src/main/resources/dt.jar";

    public static void main(String[] args) throws Exception {
        ReflexUtil.getJar(FILE);

        // 获取某类指定属性
        Field fields = TestReflect.class.getDeclaredField("serialVersionUID");
        System.out.println(fields.getName());

        // 调用某类指定方法
        Method method = TestReflect.class.getMethod("getInterfaceImplements");
        method.invoke(TestReflect.class.newInstance());

        // 调用某接口指定方法
/*        Method me = UserService.class.getMethod("findAll");
        me.invoke(TestReflect.class.newInstance());*/

        UserService impl = new UserServiceImpl();

        UserService userService = (UserService) Proxy.newProxyInstance(impl.getClass().getClassLoader(), UserServiceImpl.class.getInterfaces(), new InterfaceInvocationHandler(impl));
        userService.findAll();
    }
}
